﻿using System;
using System.Text;
using System.Web.UI;
using VitCode.Castle.DataAccess;

namespace CRS.Web.UserControls
{
    public partial class AmenuCtl : UserControl
    {
        readonly StringBuilder strHtml = new StringBuilder();
        readonly BaseDataAccess m_Acc = new BaseDataAccess();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                strHtml.Append("<ul class=\"TopMenuUl\"><table style=\" height:50px;\"><tr>");
                var dtList =
                    m_Acc.GetDataTableBySql(
                        "select Name,URLPath,IconPath,id from VitCode_Castle_Menu where parentid is null order by OrderId desc ");
                if (dtList != null && dtList.Rows.Count > 0)
                {
                    for (var i = 0; i < dtList.Rows.Count; i++)
                    {
                        strHtml.Append("<td style=\"width:50px; height:40px\">");
                        strHtml.Append(
                            "<li onmouseover=\"this.style.backgroundColor = '#CBC8FF'\" onmouseout=\"this.style.backgroundColor=''\">");
                        strHtml.Append("<a href=\"" + dtList.Rows[i]["URLPath"] +
                                       "\" target=\"frmmain\" style=\"border: 0px;\">");
                        strHtml.Append("<img class=\"TopMenuImg\" src=\"" + dtList.Rows[i]["IconPath"] + "\" title=\"" +
                                       dtList.Rows[i]["Name"] + "\" alt=\"" + dtList.Rows[i]["Name"] + "\" />");
                        strHtml.Append("</a>");
                        strHtml.Append("</li>");
                        strHtml.Append("</td>");
                    }
                }
                strHtml.Append("</tr></table></ul>");
                Response.Write(strHtml);
            }
        }
    }
}